<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
	 <form id="ligerForm" >
			<div class="fieldset1 tabel_col clearFix">
				<div class="caption">
					<span class="title">移交申请</span>
				</div>
				<div class="fieldBox col_100"></div>
			</div>
				<!-- 移交申请选择数据 -->
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_100">
					<div class="label"><font color="red">*</font>是否需要解押材料</div>
					<div class="field">
		                    <input name="isNeed" onclick="isShowInfor(1)" type="radio" value="1" >是
		                    <input name="isNeed" onclick="isShowInfor(0)" type="radio" value="0" >否
					</div>
				</div>
				<div id="jieYaInfo" style="display: none;">
					<div class="fieldBox col_100">
						<div class="label"><font color="red">*</font>解押材料申请表</div>
						<div class="field">
								<jsp:include page="/WEB-INF/views/system/sysUlFilesRec/sysUlFilesRecUploadW.jsp" flush="true" >
									<jsp:param name="filePath" value="arcfile/transfer"/>
									 <jsp:param name="fileNum" value="1"/>
								</jsp:include>
								 	<input id="tabNm"  name="tabNm"  type="hidden"  value="ARC_TRANSFER_MAIN">
							</div>
					</div>
					<!-- 解押材料申请表附件显示 -->
						<div class="fieldBox col_100">
							<div style="width: 98%; margin-left: 1%;">
								<div id="ligergrid_file1" class="sq-grid"></div>
							</div>
						</div>
						<br/>
				</div>
				<!--选择的移交数据展示-->
				<div class="fieldBox col_100">
					<div style="width: 98%; margin-left: 1%;">
						<div id="ligergrid_transfer" class="sq-grid"></div>
					</div>
				</div>
			</div>
		<div class="fieldset1 tabel_col clearFix">
			<div class="caption">
				<span class="title">接收人信息</span>
			</div>
			<div class="fieldBox col_50">
						<div class="label">工号/姓名</div>
						<div class="field">
							<input id="jobNum"  name="jobNum"   type="text"   class="ui-textbox"  ligerui="width: 160"
								value=""    />
							<a class="sq-button-hasicon" href="javascript:getSysUsr()"><i class="sqBtnIco_4"></i>查找收件人</a>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收件人（工号）</div>
						<div class="field">
							<input id="idCard"  name="arcPostInfoVO.idCard"  type="text"   class="ui-textbox"  ligerui="width: 160"  disabled="disabled"  />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收件人（姓名）</div>
						<div class="field">
							<input id="recipient"  name="arcPostInfoVO.recipient"  type="text"   class="ui-textbox"  ligerui="width: 160"   disabled="disabled"  />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">联系电话</div>
						<div class="field">
							<input id="mobile"  name="arcPostInfoVO.mobile"  type="text"   class="ui-textbox"  ligerui="width: 160" 
								value=""   validate="{mobile:true}" />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">接收方式</div>
						<div class="field">
							<select id="sendType"  name="arcPostInfoVO.sendType"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${sendTypeList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
						</div>
					</div>
					<div id="emailInfo" style="display: none;">
						<div class="fieldBox col_50">
							<div class="label">快递公司</div>
							<div class="field">
								<select id="sendCompany"  name="arcPostInfoVO.sendCompany"  ligerui="width: 160" >
										<option value="">请选择</option>
										<c:forEach items="${sendCompanyList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">快递单号</div>
							<div class="field">
								<input id="sendNum"  name="arcPostInfoVO.sendNum"  type="text"   class="ui-textbox"  ligerui="width: 160" 
									value=""    />
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">邮寄地址</div>
							<div class="field">
							<input id="sendAddr"  name="arcPostInfoVO.sendAddr"  type="text"   class="ui-textbox"  
								value=""    />
						</div>
						</div>
					</div>
				   <div class="fieldBox col_100">
						<div class="label">备注</div>
						<div class="field">
							 <textarea id="remark"  name="arcPostInfoVO.remark" rows="3" class="l-textarea" style="width:80%"></textarea>
						</div>
					</div>
					<!-- 隐藏参数 -->
	                <div class="fieldBox col_100" style="display:none;">
						<div class="field">
							<input type="text" id="isGrpBiz" name="isGrpBiz" value="${isGrpBiz}"></span>		<!--hidde date 是否团单  -->
	                        <input name="contractNo" id="contractNo" type="text" class="ui-textbox" value='${contractNo}'>
	                        <input name="payListCode" id="payListCode" type="text" class="ui-textbox" value='${paySchNo}'>
	                         <input name="arcReceiptMainId" id="arcReceiptMainId" type="text" class="ui-textbox" value='${arcMgrMainVO.arcReceiptMainId}'>
	                         <input name="prdStsCd" id="prdStsCd" type="text" class="ui-textbox" value=''>
	                         <input name="cstId" id="cstId" type="text" class="ui-textbox"  value='${cstId}'>
	                         <input name="paySchId" id="paySchId" type="text" class="ui-textbox"  value='${paySchId}'>
	                          <input  id="up_file_id" type="text" class="ui-textbox" >
	                          <input  id="up_file_path" type="text" class="ui-textbox" >
	                          <!-- 上传文件使用：系统时间和当前登录人姓名 -->
                      <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
                      <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
	                    </div>
	                </div>
		</div>
		<div class="btnsBox">
			<span id="saveBtn" class="sq-button sq-button-round" onclick="transferApplyStart();">发起移交</span>
			<span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab();">取消</span>
					
		</div>	
	</form>		
	</div>
<script type="text/javascript">
var  payIdList = "${payIdList}";//多个支付表集合
var grid2 = null;
var grid = null;
var prefixUrl='${prefixUrl}';
$(function() {
	//$("#ligerForm").ligerForm();
	$("#ligerForm").ligerForm({
        validate : true
    });
	 //initWarrantGrid();//初始化权证资料
	  initGrid();//初始化移交选择数据列表
	$("#sendType").change(function(){
		if(this.value!= "" && this.value == 0) {//邮寄
			$("#emailInfo").show();
		}else {
			$("#emailInfo").hide();
		}
	});
	//解押材料申请表附件可删除
	loadFilesLiger("jieya", 1, " ", "yes");
	 
});
//初始化列表
function initGrid(){
	$("#ligergrid_transfer").ligerGrid({
		url:'<%=path%>/archive/arcTransferMain/initTransferList.do',
		method:'get',
		parms:{'payIdList':payIdList},
		columns:[
			{ display: '承租人姓名', name: 'cstNm', minWidth: 100,
				render:function (rowdata, rowindex, value){
					return "<span title="+rowdata.cstNm+">"+rowdata.cstNm+"</span>";
				}
			},
			{ display: '合同号', name: 'contractNo', minWidth: 150,
				render:function (rowdata, rowindex, value){
					return "<span title="+rowdata.contractNo+">"+rowdata.contractNo+"</span>";
				}
			},
			{ display: '支付表号', name: 'paySchNo', minWidth: 160,
				render:function (rowdata, rowindex, value){
					return "<span title="+rowdata.paySchNo+">"+rowdata.paySchNo+"</span>";
				}
			},
			{ display: '结清时间', name: 'stlDt', minWidth: 50},
			{ display: '事业部', name: 'buOrgCdNm', minWidth: 60},
			{ display: '省公司', name: 'prOrgCdNm', minWidth: 90},
			{ display: '结清状态', name: 'prdStsCdNm', minWidth: 40,
				render:function (rowdata, rowindex, value){
					 var h="";
					 if(rowdata.prdStsCdNm=='正常'){
						 h='';
					 }else if(rowdata.prdStsCdNm=='已拖回'){
						 h='';
					 }else if(rowdata.prdStsCdNm=='拖回已转优车'){
						 h='';
					 }else{
						 h=rowdata.prdStsCdNm;
					 }
					 return h;
				 }
			},
			{ display: '纸质归档状态', name: 'storageStatusNm', minWidth: 40},
			{ display: '移交状态', name: 'transferStatusNm', minWidth: 30},
			{ display: '客户经理', name: 'cstMgrNm', minWidth: 30},
			{display:'操作',minWidth: 100,align:'left',
				  render:function (rowdata, rowindex, value){
						var h="";
						 h+='<a class="sq-button-hasicon" href="javascript:removeRow(';
						 h+="'"+rowdata+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>移除</a>";
						return h;
					}
			},
			{display:'其他资料', name: 'uploadFileList', minWidth: 120,
				 render: function (rowdata, rowindex, value) {
					 var h="";
					 h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="uploadDialog(';
					 h+="'"+rowdata.id+"'";
		             h+=",'"+rowdata.paySchNo+"'";
		             h+=")\"><i class='sqBtnIco_9'></i>上传</a>";
		             if(rowdata.uploadFileList){
 						 var listl=rowdata.uploadFileList;
 						 for(var i=0;i<listl.length;i++){
 							h+='<a   target="_blank" href="'+listl[i].filePath+'">'+listl[i].fileNm+'</a>';
 							h+=' | <a  href="javascript:uploadFileDeleteById(';
			                h+="'"+listl[i].id+"'";
			                h+=",'"+listl[i].pkId+"'";
			                h+=')"><i class="sqBtnIco_7"></i>删除</a>';
 						 }
 					 }
					 return h; 
				 }
			},
		],
		pageSize:30,
		pageSizeOptions:[30,40,50], //可指定每页页面大小
		record:'total',
		hideLoadButton:false,
		width:'100%',
		height:'100%',
		heightDiff:-2,
		isScroll: true,
		root: 'rows',
		hideLoadButton:false,
		frozen: false,
		//checkbox:true,//列表是否有选择框
		selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
		rownumbers:true,//列表是否有行号
		//选择行事件
		onSelectRow: function(rowdata, rowid, rowobj){
			
		},
		//取消选择行事件
		onUnSelectRow : function(rowdata, rowid, rowobj){
			
		},
		 detail: {
             height: 'auto',
             onShowDetail: initWarrantGrid
         }
	});
	grid = liger.get("ligergrid_transfer");
	grid.setHeight(100);
	//grid.options.isSingleCheck = true;//列表是否为单选
}
//初始化权证资料列表
function initWarrantGrid(row, detailPanel, callback) {
 var gridBox = document.createElement('div');
    $(gridBox).css('margin', 10);
    $(detailPanel).css({
        'padding': 10,
        'box-sizing': 'border-box'
    }).append(gridBox);
    detailGrid = $(gridBox).ligerGrid({
    	url:'<%=path%>/archive/arcTransferMain/initGridList.do',
    	parms:{contractNo: row.contractNo, payListCode: row.paySchNo, arcLevel: "2",fileFlag:"3"},
        method: 'get',
        columns:[
     			{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
     			{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
     			{ display: '资料类型', name: 'dossierTempNm', minWidth: 160, align: 'center', enabledSort: true},
     			{ display: '存档份数', name: 'dossierCountT', minWidth: 160, align: 'center', enabledSort: true},
     			{ display: '已移交份数', name: 'transferCount', width: 90, align: 'center', enabledSort: true,
     				render:function (rowdata, rowindex, value){
     					return "<span>"+0+"</span>";
     				}
     			}
     			
     		],
        root: 'rows',
        hideLoadButton: true,
        width: '100%',
        height: 'auto',
        isScroll: false,
        rownumbers: true,  //显示序号
        checkbox: false,
        allowUnSelectRow: true,
        alternatingRow: true,
        onAfterShowData: callback,
        frozen: false,
        usePager: false
    });
 	//$('#otherInfo').style.display="block";
 	//document.getElementById('otherInfo').style.display="";
}
//查找收件人 
function getSysUsr(){
	
	if($.trim($("#jobNum").val()) == ""){
		$.ligerDialog.SQalert({content: "请填写工号/姓名",SQ_type: "warning"});
		return;
	}
	var ligerForm = liger.get("ligerForm");
	if (!ligerForm.valid()) {
	    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
            return false ; 
     }
		
	 $.ajax({
		type: 'get',
		dataType:'json',
		url: '<%=path%>/archive/arcTransferMain/getSysUsr.do?jobNum='+$("#jobNum").val(),
		success:function(msg){
			//console.log(msg);
			 if(msg.success == 1){
				 if(msg.data){
					 $("#idCard").val(msg.data.usrNm);
					 $("#recipient").val(msg.data.refRlNm);
					 $("#mobile").val(msg.data.mp);
				 }else{
					 $.ligerDialog.SQalert({content:"没有查询到对应人员", SQ_type: "warning"});
					 $("#idCard").val("");
					 $("#recipient").val("");
					 $("#mobile").val("");
				 }
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	}); 
}
//发移交申请
function transferApplyStart(){
	var ligerForm = liger.get("ligerForm");
	 //isNeed 是否需要解押材料
	 var isNeed=$("input[type='radio']:checked").val();
	 if(isNeed=='undefined' || isNeed=='' || isNeed==null){
		 $.ligerDialog.SQalert({content: "请选择是否需要解押材料，再发起流程",SQ_type: "warning"});
		return ; 
	 }
	 if(isNeed==1){
		var jiya= $('#up_file_id').val();
		if(jiya==''||jiya==null || jiya=='undefined'){
			 $.ligerDialog.SQalert({content: "请上传解押材料申请表，再发起流程",SQ_type: "warning"});
			return ;
		}
	 }
	
	//组装一下最终的支付表ID集合（有可能有移除操作）
	var payIdStr="";
	var warrantJson=grid.getData();
	console.log(typeof warrantJson );
	console.log("tt"+ warrantJson );
	//判断一下支付表不能为空
	if(warrantJson == null || warrantJson==''){
		 $.ligerDialog.SQalert({content: "请至少保留一条支付表数据，再发起移交流程",SQ_type: "warning"});
		 return ;
	}
	for(var p in warrantJson){//遍历json数组时，这么写p为索引，0,1
		payIdStr=payIdStr+warrantJson[p].paySchId+",";
	}
	payIdStr = payIdStr.substring(0, payIdStr.lastIndexOf(','));
	
	 var re=jycheckStart(payIdStr);//校验客户是否有小贷（用组装后的支付表ID集合）
	 console.log(re);
	 if(re.data=='1' || re.data =='2'){
		$.ligerDialog.SQalert({content: re.info,SQ_type: "warning"});
		return ;
	 } 
	
	//2检查邮寄信息
	if($.trim($("#idCard").val()) == ""){
			$.ligerDialog.SQalert({content: "输入工号，点击'查找收件人'，查询出收件人（工号）和收件人（姓名）",SQ_type: "warning"});
			return ;
	} 
   if($.trim($("#mobile").val()) == ""){
		$.ligerDialog.SQalert({content: "请填写联系电话",SQ_type: "warning"});
		return ;
	} 
   if($.trim($("#sendType").val()) == ""){
		$.ligerDialog.SQalert({content: "请选择接收方式",SQ_type: "warning",SQ_showButtons: true});
		return ;
	} 
    if($.trim($("#sendType").val()) == 0){
	   /* if($.trim($("#sendCompany").val()) == ""){
			$.ligerDialog.SQalert({content: "请选择快递公司",SQ_type: "warning",SQ_showButtons: true});
			return ;
		} 
	   if($.trim($("#sendNum").val()) == ""){
			$.ligerDialog.SQalert({content: "请输入快递单号",SQ_type: "warning",SQ_showButtons: true});
			return ;
		} */
	   if($.trim($("#sendAddr").val()) == ""){
			$.ligerDialog.SQalert({content: "请输入邮寄地址",SQ_type: "warning",SQ_showButtons: true});
			return ;
		}
	} 
   
	//3 、组织数据
	var data = ligerForm.getData();
	data["contractNo"] ='${contractNo}';
	data["paySchNo"] ='${paySchNo}';
	data["prdStsCd"] ='${prdStsCd}';
	data["bizTypCd"]='${bizTypCd}';
	data["buOrgCd"]='${buOrgCd}';
	data["cstNm"]='${cstNm}';
	data["_arcTransferMainList"] =JSON.stringify(grid.getData());//移交数据
	data["portfolioNumber"] = '${arcMgrMainVO.portfolioNumber}';//总公司档案袋编号
	data["portfolioNumberProvince"] = '${arcMgrMainVO.portfolioNumberProvince}';//省公司档案袋编号
	data["up_file_id"]=$('#up_file_id').val();//*解押材料申请表id
	data["up_file_path"]=$('#up_file_path').val();//*解押材料申请表filepath
	
	console.log(data);
	
	
	var wait_dialog = null;
	$.ajax({
		type: 'post',
		dataType: 'json',
		data: data,
		url: '<%=path%>/archive/arcTransferMain/transferApplyStartN.do?',
		beforeSend: function(){
			wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
		},success:function(msg){
			wait_dialog.close();
			if(msg.success == 1){
					//$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
					alert(msg.info);
					Remove_navTab();//关闭当前页面
			}else{
				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			}
		},error:function (XMLHttpRequest, textStatus, errorThrown) { 
			wait_dialog.close();
			$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
		} 
	});
}

//1 核查该支付表下有未归还权证资料，请先结束流程  2 //校验客户是否有小贷
function   jycheckStart(payIdList){
	// re=1 1 核查该支付表下有未归还权证资料，请先结束流程  2 客户是否有小贷
	var re=0;
	var data;
	//var paySchId=$('#paySchId').val();
	//var cstId=$('#cstId').val();
	$.ajax({
		type: 'post',
		dataType: 'json',
		async:false,
		data: {'payIdList':payIdList},
		url: '<%=path%>/archive/arcTransferMain/checkStartProcessBatch.do?',
		beforeSend: function(){
			wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
		},success:function(msg){
			wait_dialog.close();
			data=msg;
			/* if(msg.data == 1){
				re=1;
			}else{
				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			} */
		},error:function (XMLHttpRequest, textStatus, errorThrown) { 
			wait_dialog.close();
			$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
		} 
	});
	return data;
}
//校验是否小贷
function   jycheck(paySchId,cstId){
	// Code: 0 失败  1 成功
	var re=0;
	//var paySchId=$('#paySchId').val();
	//var cstId=$('#cstId').val();
	$.ajax({
		type: 'post',
		dataType: 'json',
		async:false,
		data: {'paySchId':paySchId,'cstId':cstId},
		url: '<%=path%>/archive/arcTransferMain/checkSmallLoan.do?',
		beforeSend: function(){
			wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
		},success:function(msg){
			wait_dialog.close();
			if(msg.data == 1){
				re=1;
			}else{
				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			}
		},error:function (XMLHttpRequest, textStatus, errorThrown) { 
			wait_dialog.close();
			$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
		} 
	});
	return re;
} 
//是否显示解押材料 解押材料申请表
function isShowInfor(val){
	var isNeed=$("input[type='radio']:checked").val();
	var trdata = grid.getRow("0"); 
	if(val=='1'){
		$('#jieYaInfo').show();
		grid.extendDetail(trdata);
	}else if(val=='0'){
		$('#jieYaInfo').hide();
		grid.collapseDetail(trdata); 
	}
}
//移除移交数据
function removeRow(rowdata){
	var manager = $("#ligergrid_transfer").ligerGetGridManager();
	manager.deleteSelectedRow();
}
//上传回调
function  uploadCallback(fileData){
	
	var params = {};
		  params.fileNm=fileData[0].fileNm;
		  params.filePath=fileData[0].filePath;
		  params.tabNm = "ARC_TRANSFER_MAIN";
		  params.cfgCd ="ARC001";
		  params.cfgDtlCd ="30";
    var url = '<%=path%>/archive/arcTransferMain/saveUploadRecord.do';
    $.ajax({
		type: 'post',
		dataType:'json',
		data:params,
		url: url,
		success:function(msg){
			 if(msg.success == 1){
				var dat = msg.data;
			    $('#up_file_id').val(dat.id);
			    $('#up_file_path').val(fileData[0].filePath);
			    showFiles(fileData,1,dat.id);//解押申请表
				//parent.$(".l-dialog,.l-window-mask").css("display","none"); 
			 }else{
				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			 }
		}
	});
}
//显示已上传但是未保存的文件列表
function showFiles(data, index,id){
	var sysDate = $("#sysDate").val();
	var loginUsrNm = $("#loginUsrNm").val();
	var f_Grid = liger.get("ligergrid_file"+index);
	var trdata = f_Grid.getRow("0");
	//删除之前上传的文件
	if(trdata!=null){
		f_Grid.deleteRow(trdata);
	} 
	//deleteRow
	var uploadJOSN = data;
	for (var i=0; i< uploadJOSN.length; i++){ 
		//添加行-追加行
		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: id,filePath:prefixUrl+uploadJOSN[i].filePath});
	}
}
//上传其他资料
function uploadDialog(id,paySchNo){
	$.ligerDialog.SQopen({
        width: 300,
        height:200,
        title : '上传其他资料',
        url:'<%=path%>/archive/arcTransferMain/toUpload.do?id='+id+'&paySchNo='+paySchNo,
        // 自定义buttons的时候 不要设置 fixButtons: true
        buttons: [ {
            text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
            onclick: function (item, Dialog) {
                //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                if (Dialog.onCancel) Dialog.onCancel();
            }
        }
        ]
    });
}
function uploadFileDeleteById(id,pkId){
	if(!id){
		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
		return;
	}
	$.ligerDialog.confirm('确定删除吗?', function (flag) {
		if(flag == false)return;
		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{id:id},
			url: '<%=path%>/system/sysulfilesrec/removeById.do',
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				wait_dialog.close();
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					 grid.reload();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	});
}
</script>
<!-- 显示上传文件列表 -->
<script type="text/javascript">
var fileGrid = null;

//加载所有文件列表：标识、序号、主键、是否可删除
function loadFilesLiger(flag, index, pkId, isDel){
	var param = null;
	var ligerNm = "ligergrid_file"+index;
	var _url = '<%=path%>/rfbuss/fncPrjContDetail/initFilesList.do';
	if(flag == "jieya"){//解押材料申请表
		param = {
				pkId: pkId,//ID
				tabNm: "ARC_TRANSFER_MAIN",
				cfgDtlCd:"30",
				cfgCd:"ARC001"
		};
	}else if(flag == "qian"){//移交申请-签收单
		param = {
				pkId: pkId,//ID
				tabNm: "ARC_TRANSFER_MAIN",
				cfgDtlCd:"80",
				cfgCd:"ARC001"
		};
	}
	
    load_FileList(flag, ligerNm, _url, param, index, isDel);
}

//加载
function load_FileList(flag, ligerNm, _url, param, index, isDel){
	$("#"+ligerNm).ligerGrid({
			usePager: false,
			url: _url,
			method : 'get',
			parms:param,
			columns:getColumns(flag, index, isDel),//动态获取列
			pageSize:10,
			root:'rows',
			 height: 'auto',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			rownumbers:true,
			checkbox:true,//列表是否有选择框
			onAfterShowData: function () {
				$( ".gridTip").grid_ligerTip();
				SetIframe_height ();
			}
	});
	fileGrid = liger.get(ligerNm);
	fileGrid.options.isSingleCheck = false;//列表是否为单选
}

//获取列表列
function getColumns(flag, index, isDel){
	var col_data = [
			{ display: '名称', name: 'fileNm', minwidth: 200, enabledSort:true },
			{ display: '提交人员', name: 'crtUsrRlNm', width: 200, enabledSort:true },
			{ display: '提交时间', name: 'crtTm', width: 200, render:renderDate2, enabledSort:true },
			getGridOperColumnWarrant(flag, index, isDel)//操作列
		];
	return col_data;
}

//文件从数据库删除 操作列
function getGridOperColumnWarrant(flag, index, isDel){
	var data = {
		display: '操作',
		isSort: false,
		minWidth: 100,
		render: function (rowdata, rowindex, value){
			var h="";
			h+='<a class="sq-button-hasicon" href="javascript:uploadFileByUrl(';
            h+="'"+rowdata.filePath+"'";
            h+=",'"+rowdata.fileNm+"'";
            h+=')"><i class="sqBtnIco_8"></i>下载</a>';
			//是否有删除操作
			if(null != flag && "hkb" != flag && isDel == "yes"){
				h+='<a class="sq-button-hasicon" href="javascript:uploadFileDeleteRow1(';
				h+="'"+rowdata.id+"'";
				h+=",'"+index+"'";
				h+=')"><i class="sqBtnIco_7"></i>删除</a>';
			}
			return h;
		}
	};
	return data;
}
//下载文件方法
function uploadFileByUrl(_url,_name){
	if(SQ.regs.img.test(_name)){
		SQ.imgPreview(_url, true);
	}else{
		window.open(_url);
	}
}

//删除调用方法
function uploadFileDeleteRow1(id, index){
	if(!id){
		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
		return;
	}
	$.ligerDialog.confirm('确定删除吗?', function (flag) {
		if(flag == false)return;
		var wait_dialog = null;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{id:id},
			url: '<%=path%>/system/sysulfilesrec/removeById.do',
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					liger.get("ligergrid_file"+index).reload();//刷新
					if(index=='1'){
						$('#up_file_id').val("");//清空上传文件
					}
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			}
		});
	});
}



//格式化时间2：YYYY-MM-DD
function renderDate2(rowdata, index, value){
	var dateStr = "";
	if(null != value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
	}
	return dateStr;
}
</script>
</body>
</html>
